package com.touchwisdom.fetch.core.web;

import org.apache.commons.lang3.StringUtils;

import com.touchwisdom.fetch.core.model.TFileFetch;
import com.touchwisdom.modular.common.util.ClassPathRender;
import com.touchwisdom.modular.common.web.BaseDataGridController;
import com.touchwisdom.modular.util.config.YesNoType;
import com.touchwisdom.modular.util.constant.StringConstUtil;

public class FileFetchController extends BaseDataGridController<TFileFetch> {
	@Override
	public void edit() {
		this.render(new ClassPathRender("/templates/fetch/file/edit.html"));
	}

	public void startTask() {
		String[] ids = StringUtils.split(this.getPara("ids"), StringConstUtil.COMMA);
		if (ids != null) {
			TFileFetch fetch = null;
			for (String id : ids) {
				fetch = TFileFetch.dao.findById(id);
				fetch.setState(YesNoType.Y.name());
				fetch.update();
			}
		}
	}

	@Override
	protected String getIndexViewFile() {
		return "/templates/fetch/file/index.html";
	}

	public void stopTask() {
		String[] ids = StringUtils.split(this.getPara("ids"), StringConstUtil.COMMA);
		if (ids != null) {
			TFileFetch fetch = null;
			for (String id : ids) {
				fetch = TFileFetch.dao.findById(id);
				fetch.setState(YesNoType.N.name());
				fetch.update();
			}
		}
	}
}